package com.etc.service.impl;

import com.etc.dao.FocusDao;
import com.etc.entity.Concern;
import com.etc.entity.History;
import com.etc.entity.Room;
import com.etc.service.FocusService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 *
 * @author makejava
 * @since 2021-10-18 21:07:18
 */
@Service
public class FocusServiceImpl implements FocusService {

    @Autowired
    FocusDao dao;

    /**
     * 添加关注
     * @param userId
     * @param roomId
     * @return
     */
    @Override
    public boolean addConcern(String userId,String roomId){
        
        return dao.setRoomOfConcernAdd(roomId)>0&&dao.focusRoomById(userId,roomId)>0;
    }
    /**
     * 取消关注
     * @param userId
     * @param roomId
     * @return
     */
    @Override
    public boolean deleteConcernById(String userId, String roomId) {
        return dao.setRoomOfConcernDel(roomId)>0&&dao.deleteConcernById(userId,roomId)>0;
    }
    /**
     * 添加历史记录
     * @param userId
     * @param roomId
     * @return
     */
    @Override
    public boolean addHistory(String userId, String roomId, String videoId) {
        if ( dao.queryHistoryById(userId,roomId,videoId)!=null){
            return dao.updateHistoryOfDate(userId,roomId,videoId)>0;
        }else{
            return dao.addHistory(userId,roomId,videoId)>0;
        }
    }
    /**
     * 根据用户id和房间id查询关注表
     * @param userId
     * @param roomId
     * @return
     */
    @Override
    public boolean queryConcernByUserIdAndRoomId(String userId, String roomId) {
        System.out.println("DEBUG测试"+dao.queryConcernByUserIdAndRoomId(userId,roomId));
        return dao.queryConcernByUserIdAndRoomId(userId,roomId)!=null;
    }

    /**
     * 关注分页
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Concern> getConcernList(String userId,int pageNo, int pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Concern> concerns = dao.queryConcernList(userId);
        PageInfo<Concern> pageInfo = new PageInfo<>(concerns);
        return pageInfo;
    }

    /**
     * 历史记录分页
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<History> getHistoryList(String userId,int pageNo, int pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<History> histories = dao.queryHistoryList(userId);
        PageInfo<History> pageInfo = new PageInfo<>(histories);
        return pageInfo;
    }
}
